package com.hancai.task;

import com.hancai.BsServerApplication;
import com.hancai.model.TClient;
import com.hancai.service.impl.ClientServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author 涵菜
 * @version 1.0
 */
//开启定时任务
@EnableScheduling
@Component
public class DataTask {

    @Resource
    private ClientServiceImpl clientService;

    //确定的延时时间，单位是毫秒
    @Scheduled(fixedDelayString = "${project.task.delay}",zone="Asia/Shanghai",timeUnit = TimeUnit.MILLISECONDS,initialDelay = 1000)
    public void task() {
        System.out.println("定时任务业务逻辑执行....."+new Date());
        //查询所有状态正常的客户
        List<TClient> tClientList = clientService.getAllOnSaleProduct();
        BsServerApplication.cacheMap.put("client",tClientList);
    }
}
